/*
 * Group 3, User Interface Programming II (vt11)
 * Pooya | Flora | Monica | Can
 */
package vical.view.model;

import javax.swing.AbstractListModel;
import javax.swing.ComboBoxModel;
import vical.model.Priority;

/**
 * This a model to store priorities in ComboBox
 * The stored data and displayed priority can be different.
 * 
 * @author Can
 */
public class PriorityComboBoxModel
        extends AbstractListModel
        implements ComboBoxModel {

    private Priority[] priorities;
    private int selectedIndex;

    public PriorityComboBoxModel() {
        this.priorities = new Priority[]{
                    new Priority(Priority.HIGH),
                    new Priority(Priority.MEDIUM),
                    new Priority(Priority.LOW)
                };
        this.selectedIndex = 0;
    }

    public String getSelectedPriority() {
        return priorities[selectedIndex].getPriority();
    }

    public int getSize() {
        return priorities.length;
    }

    public Object getElementAt(int index) {
        return priorities[index].getDisplayPriority();
    }

    public void setSelectedItem(Object anItem) {
        for (int i = 0; i < priorities.length; i++) {
            if (priorities[i].getDisplayPriority().equals(anItem)) {
                this.selectedIndex = i;
                return;
            }
        }
        this.selectedIndex = -1;
    }

    public Object getSelectedItem() {
        return priorities[selectedIndex].getDisplayPriority();
    }
}
